<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>Arvato企业微信后台管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">权限管理</a>
        <a>
          <cite>角色列表</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="weadmin-body">
			<div class="weadmin-block">
				<button class="layui-btn" onclick="WeAdminShow('增加角色','./role-add.html')"><i class="layui-icon"></i>增加</button>
				<span class="fr" style="line-height:40px"></span>
			</div>
			<!--  角色表格 -->
			<table class="layui-table" lay-filter="role_table" id="role_table" style="margin: 0"></table>
		</div>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/jquery-1.8.0.min.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js" charset="utf-8"></script>
		<script>
			layui.use('table', function() {
				var table = layui.table;
				// 加载用户数据表格
				window.roleTable = table.render({
					id: 'roleTable',
					elem: '#role_table',
					url: commonUtil.domain() + '/admin/right/role/list', //数据接口
					method: 'post',
					page: true, //开启分页
					request: {
						pageName: 'pageNum', // 分页当前页数发给后台的参数名
						limitName: 'pageSize' // 分页每页多少条发给后台的参数名
					},
					done: function(res) {
						$('.layui-laypage-count').text('共' + res.total + '条')
					},
					cols: [
						[ //表头
							{
								field: 'roleName',
								title: '角色名称',
								width: 100
							}, {
								field: 'roleDescribe',
								title: '角色描述',
								width: 430
							}, {
								field: 'resourceStr',
								title: '资源集合',
								width: 510
							}, {
								field: 'status',
								title: '状态',
								width: 80,
								templet: '#status'
							}, {
								field: 'oper',
								title: '操作',
								width: 75,
								templet: '#oper'
							}
						]
					]
				});
				// 刷新表格
				roleTable.refresh = function(data) {
					roleTable.reload({
						where: data,
						page: {
							curr: 1 // 重新从第 1 页开始
						}
					});
				}
				// 监听表格点击删除和修改按钮
				table.on('tool(role_table)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					var data = obj.data; // 获得当前行数据
					var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					var tr = obj.tr; // 获得当前行 tr 的DOM对象
					var roleId = data.roleId;
					if(layEvent === 'update') {
						WeAdminShow('修改角色', './role-add.html?roleId=' + data.roleId)
					} else if(layEvent === 'delete') {
						layer.confirm('确认要删除此角色吗？', function(index) {
							// 删除用户
							var ajaxParam = {
								url: commonUtil.domain() + '/admin/right/role/delete',
								data: {
									roleId: roleId
								}
							}
							ajaxUtil.post(ajaxParam, function(data) {
								if(data.code == 200) {
									layer.alert("删除成功", {
										icon: 6
									}, function() {
										roleTable.refresh();
										layer.closeAll();
									});
								} else {
									layer.alert(data.msg);
								}
							});
						});
					}
				});
			});
		</script>
		<script>
			$(function() {
				commonUtil.setMaxLength(40);
			})
		</script>
		<script type="text/html" id="oper">
			<a title="修改" lay-event="update"><i class="layui-icon">&#xe642;</i></a>
			<a title="删除" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
		</script>
		<script type="text/html" id="status">
			{{# if(d.status == 1){ }}
			<span class="layui-btn layui-btn-normal layui-btn-xs">正常</span> {{# } else { }}
			<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">禁用</span> {{# } }}
		</script>
	</body>

</html>